package com.kazalan.domain.document;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import com.kazalan.domain.BaseObject;

public class DocumentAggregate extends BaseObject implements Serializable {

	private static final long serialVersionUID = -268949523204674182L;

	private Set<Document> documents;

	public DocumentAggregate() {
		super();
		this.documents = new HashSet<Document>();
	}

	public void addDocument(Document document) {
		this.documents.add(document);
	}

	public void setDocuments(Set<Document> documents) {
		this.documents = documents;
	}

	public Set<Document> getDocuments() {
		return documents;
	}

	public Document getDocumentByLanguage(Language language) {

		for (Document document : documents) {
			if (document.getLanguage().equals(language)) {
				return document;
			}
		}

		return null;
	}

	@Override
	public String toString() {
		return new StringBuilder().append("Aggregate ID : " + getId())
				.append("\r").append(documents).toString();
	}
}
